package ist.utl.pt.smartfleet.stationterminal;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Initial extends Activity{

	private EditText mID;
	private EditText mNetPort;
	private EditText mEmulPort;
	private EditText mSimAddr;
	private EditText mSimPort;
	private EditText mCentralAddr;
	private EditText mCentralPort;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.initial);
        
        Button confirmButton = (Button) findViewById(R.id.confirm);
        
        mID = (EditText) findViewById(R.id.id_text);
        mNetPort = (EditText) findViewById(R.id.netport_text);
        mEmulPort = (EditText) findViewById(R.id.emulport_text);
        mSimAddr = (EditText) findViewById(R.id.sim_address);
        mSimPort = (EditText) findViewById(R.id.sim_port);
     //   mCentralAddr = (EditText) findViewById(R.id.central_address);
     //   mCentralPort = (EditText) findViewById(R.id.central_port);
        
        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                Bundle bundle = new Bundle();
                
                String id =  mID.getText().toString();
                String netPort = mNetPort.getText().toString();
                String emulPort = mEmulPort.getText().toString();
                String simAddr = mSimAddr.getText().toString();
                String simPort = mSimPort.getText().toString();
                
                if(id.compareTo("") == 0 || netPort.compareTo("") == 0 || emulPort .compareTo("") == 0 || 
                		simAddr.compareTo("") == 0 || simPort.compareTo("") == 0)
                	Toast.makeText(Initial.this, "Preencher todos os campos", Toast.LENGTH_SHORT).show();
                
                else{

                	bundle.putString("id", mID.getText().toString());
                	bundle.putString("netport", mNetPort.getText().toString());
                	bundle.putString("emulport", mEmulPort.getText().toString());
                	bundle.putString("sim_addr", mSimAddr.getText().toString());
        	        bundle.putString("sim_port", mSimPort.getText().toString());
        	    //  bundle.putString("central_addr", mCentralAddr.getText().toString());
                //  bundle.putString("central_port", mCentralPort.getText().toString());
                
        	        Intent mIntent = new Intent();
        	        mIntent.putExtras(bundle);
        	        mIntent.addFlags(2);
        	        setResult(RESULT_OK, mIntent);
        	        finish(); 
                }
            }
        });
	}
}